package com.wsl.controller;

import com.wsl.bean.User;
import com.wsl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 19:31 2017/10/31
 * @Modified by:
 */
@RestController
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    JedisPool jedisPool;

    @RequestMapping(value = "/test", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getById() {
        Long a = 1L;
        String key = a.toString() + "wsl";
        Jedis jedis = jedisPool.getResource();
        String str = jedis.get(key);
        User user = null;
        if (str == null) {
            System.out.println("缓存中没有直接去查数据库。。。");
            user = userService.getByID(a);
            jedis.set(key, user.toString());
            str = user.toString();
        }
        return str;
    }
}